import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:photo_view/photo_view_gallery.dart';
import 'package:pplive/models/moment_model.dart';

class PhotoPage extends StatefulWidget {
  const PhotoPage({super.key});

  @override
  State<StatefulWidget> createState() => _PhotoState();
}

class _PhotoState extends State<PhotoPage> {
  Moment model = Get.arguments as Moment;
  int pageIndex = 0;

  @override
  Widget build(BuildContext context) {
    var itemCount = model.picUrls.length;
    var title = "${pageIndex + 1}/$itemCount";
    return Scaffold(
        appBar: AppBar(
          title: Text(title),
        ),
        body: SafeArea(
            child: Container(
                color: Colors.black,
                child: Padding(
                  padding: const EdgeInsets.fromLTRB(13, 0, 13, 0),
                  child: SafeArea(
                    child: PhotoViewGallery.builder(
                        itemCount: model.picUrls.length,
                        onPageChanged: (index) => setState(() => pageIndex = index ),
                        builder: (context, index) {
                          return PhotoViewGalleryPageOptions(
                              imageProvider:
                                  NetworkImage(model.picUrls[index]));
                        }),
                  ),
                )))
    );
  }
}
